package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Department;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private IDepartmentService iDepartmentService;

//    分页查询
    @RequestMapping("/list")
    @RequiredPermission(name = "部门查询",expression = "/list")
    public String list(Model model, QueryObject qo){
        PageInfo<Department> que = iDepartmentService.que(qo);
        int i=1/0;
        model.addAttribute("pageInfo",que);
        return "department/list";
    }

//    删除
    @RequestMapping("/delete")
    public  String delete(Long id){
        if (id!=null){
            iDepartmentService.deleteByPrimaryKey(id);
        }
        return "redirect:/department/list";
    }

//    新增/修改
    @RequestMapping("/input")
    public String input(Long id,Model model){
        if (id!=null){
            model.addAttribute("department",iDepartmentService.selectByPrimaryKey(id));
        }
        return "/department/input";
    }
//保存或者修改
    @RequestMapping("/saveOrUpdate")
    @RequiredPermission(name = "部门增加",expression = "/inputttt")
    public String saveOrUpdate(Department department){
        if (department.getId()!=null){
            iDepartmentService.updateByPrimaryKey(department);
        }else {
            iDepartmentService.insert(department);
        }
        return "redirect:/department/list";
    }

}
